<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象转查询字符串</title>
</head>
<body>
    <script>
        // 目标: 对象 -> 查询字符串 
        let obj = {
            id: 10,
            name: '小李',
            age: 18
        }
        // 1. for...in遍历对象
        let str = ``;
        for (let prop in obj) {
            // 2. 拼接字符串
            str += `${prop}=${obj[prop]}&`
        }
        // 3. 截取字符串, 不要最后一位多余&
        str = str.substr(0, str.length - 1)
        console.log(str);
       
    </script>
</body>
</html>